home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / bother__ / cenvid.zip / CENVIDOS.ZIP / SCREEN.LIB < prev    next >
Text File  |  1995-03-28  |  10KB  |  283 lines

  1. //**********************************************************************
  2. //*** Screen.lib - A library of useful utilities for writing to the  ***
  3. //*** ver.3        screen. For when the internal CEnviD Screenxxx() ***
  4. //***              routines are not enough.                          ***
  5. //***
  6. //***
  7. //**** SetCursor(): Set cursor at screen Row and Column
  8. // SYNTAX: void SetCursor(int Row,int Col)
  9. //
  10. //**** GetCursor(): Get current cursor position
  11. // SYNTAX: void GetCursor(int Row,int Col)
  12. //
  13. //**** ScrWrite(): Write string or character, position, and attributes
  14. // SYNTAX: void ScrWrite(string Text or byte Char)
  15. //         void ScrWrite(string Text or byte Char,int Row,int Col)
  16. //         void ScrWrite(string Text or byte Char,int Row,int Col,int ForeColor,int BackColor)
  17. // WHERE: Text - Character string to write
  18. //        Row, Col - Cursor position; if not supplied then current position
  19. //        ForeColor, BackColor - Attributes for string, else current attributes
  20.    #define BLACK           0
  21.    #define BLUE            1
  22.    #define GREEN           2
  23.    #define CYAN            3
  24.    #define RED             4
  25.    #define MAGENTA         5
  26.    #define BROWN           6
  27.    #define LIGHTGRAY       7
  28.    #define DARKGRAY        8
  29.    #define LIGHTBLUE       9
  30.    #define LIGHTGREEN      10
  31.    #define LIGHTCYAN       11
  32.    #define LIGHTRED        12
  33.    #define LIGHTMAGENTA    13
  34.    #define YELLOW          14
  35.    #define WHITE           15
  36.    #define BLINK           0x8  // OR with background color to make blink
  37. //
  38. //**** Clear(): Clear screen
  39. // SYNTAX: void Clear()
  40. //         void Clear(ForeColor,BackColor)
  41. //
  42. //**** Scroll(): Scroll a region of the screen
  43. // SYNTAX: void Scroll(LineCount)
  44. //         void Scroll(LineCount,TopRow,LeftCol,BottomRow,RightCol)
  45. //         void Scroll(LineCount,ForeColor,BackColor)
  46. //         void Scroll(LineCount,TopRow,LeftCol,BottomRow,RightCol,ForeColor,BackColor)
  47. //
  48. //**** TextBox()
  49. // SYNTAX: void TextBox(TopRow,LeftCol,BottomRow,RightCol)
  50. //         void TextBox(TopRow,LeftCol,BottomRow,RightCol,Treatment)
  51. //         void TextBox(TopRow,LeftCol,BottomRow,RightCol,ForeColor,BackColor)
  52. //         void TextBox(TopRow,LeftCol,BottomRow,RightCol,ForeColor,BackColor,Treatment)
  53. // WHERE: Treatment is a character to use as the border (e.g. '*') or'ed with one of the following
  54.    #define DOUBLE_LINE  0x100 // Use double-line graphics characters
  55.    #define SINGLE_LINE  0x200 // use single-line graphics characters around box
  56.    #define SHADOW       0x400 // drop down a shadow from the box to desktop
  57.    #define NOFILL       0x800 // only draw border
  58. //
  59. //**** ReadCharacter()
  60. // SYNTAX: byte ReadCharacter()
  61. //         byte ReadCharacter(int Attribute)
  62. //         byte ReadCharacter(int Row,int Col)
  63. //         byte ReadCharacter(int Row,int Col,int Attribute)
  64. //
  65. //
  66. //**** GetScreenData() - Read screen text into one single array
  67. // SYNTAX byte[] ReadScreen()
  68. // RETURN: An array is returned of screenwidth * screenheight bytes containing
  69. //         the contents of the screen; No attempt is made to turn NULLs into
  70. //         spaces or to end lines
  71. //
  72. //
  73. //**** SetCursorType()
  74. // SYNTAX: void SetCursorType(int Cursor)
  75. //         void SetCursrorType(int StartingLine,int EndingLine)
  76.    #define HIDE_CURSOR 0xFFFF
  77. //
  78. //**** GetCursorType()
  79. // SYNTAX: int GetCursorType()
  80. //
  81. //**** SetAttribute()
  82. // SYNTAX: void SetAttribute(int Attribute)
  83. //         void SetAttribute(int ForeColore,int BackColor)
  84. //
  85. //**** HorzLine(): Draw a horizontal line
  86. // SYNTAX: void HorzLine(Row,LeftCol,Treatment)
  87. //         void HorzLine(Row,LeftCol,Len,ForeColor,BackColor,Treatment)
  88. // WHERE: Treatment is SINGLE_LINE, DOUBLE_LINE, or character to draw with
  89. //
  90. //**** VertLine(): Draw a vertical line
  91. // SYNTAX: void VertLine(TopRow,Col,Treatment)
  92. //         void VertLine(TopRow,Col,Len,ForeColor,BackColor,Treatment)
  93. // WHERE: Treatment is SINGLE_LINE, DOUBLE_LINE, or character to draw with
  94. //
  95. //
  96. //
  97.  
  98. slForeColor = LIGHTGRAY;
  99. slBackColor = BLACK;
  100.  
  101.  
  102. SetCursor(pRow,pCol)
  103. {
  104.    reg.ah = 2, reg.bh = 0, reg.dh = pRow, reg.dl = pCol;
  105.    interrupt(0x10,reg);
  106. }
  107.  
  108. GetCursor(pRow,pCol)
  109. {
  110.    reg.ah=3, reg.bh=0;
  111.    interrupt(0x10,reg);
  112.    pRow=reg.dh, pCol=reg.dl;
  113. }
  114.  
  115. SetCursorType(pStartingLine,pEndingLine)
  116. {
  117.    lCursor = ( 1 == va_arg() ) ? pStartingLine : (pStartingLine<<8) | pEndingLine ;
  118.    reg.ah=1, reg.cx=lCursor;
  119.    interrupt(0x10,reg);
  120. }
  121.  
  122. GetCursorType()
  123. {
  124.    reg.ah=3, reg.bh=0;
  125.    interrupt(0x10,reg);
  126.    return reg.cx;
  127. }
  128.  
  129. SetAttribute(pForeColor,pBackColor)
  130. {
  131.    if ( 1 == va_arg() )
  132.       slForeColor = pForeColor & 0xF, slBackColor = (pForeColor & 0xF0) >> 4;
  133.    else
  134.       slForeColor = pForeColor, slBackColor = pBackColor;
  135. }
  136.  
  137. ReadCharacter(pRow,pCol,pAttr)
  138. {
  139.    if ( 1 < va_arg() ) SetCursor(pRow,pCol);
  140.    reg.ah=8, reg.bh=0;
  141.    interrupt(0x10,reg);
  142.    if ( 1 == va_arg() ) pRow = reg.ah;
  143.    else if ( 3 == va_arg() ) pAttr = reg.ah;
  144.    return byte(reg.al);
  145. }
  146.  
  147. ScrWrite(pStrOrChar,pRow,pCol,pForeColor,pBackColor)
  148. {
  149.    if ( 3 < va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  150.    if ( !DataDimension(pStrOrChar) ) {
  151.       // write a single character
  152.       if ( 1 < va_arg() ) ScreenCursor(pCol,pRow);
  153.       reg.ah=9, reg.cx=1, reg.al=pStrOrChar;
  154.    } else {
  155.       // write a string
  156.       if ( 1 < va_arg() ) reg.dh=pRow, reg.dl=pCol;
  157.       else GetCursor(reg.dh,reg.dl);
  158.       reg.ax=0x1301, reg.cx=strlen(pStrOrChar);
  159.       reg.es=segment(pStrOrChar), reg.bp=offset(pStrOrChar);
  160.    }
  161.    reg.bx=slForeColor|(slBackColor<<4);
  162.    interrupt(0x10,reg);
  163. }
  164.  
  165. Clear(pForeColor,pBackColor)
  166. {
  167.    if ( 2 == va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  168.    lSize = ScreenSize();
  169.    Scroll(0,0,0,lSize.row-1,lSize.col-1);
  170. }
  171.  
  172. Scroll(pLineCount,pTopRow,pLeftCol,pBottomRow,pRightCol,pForeColor,pBackColor)
  173. {
  174.    if ( pLineCount < 0 ) reg.ah=6, reg.al=-pLineCount;
  175.    else reg.ah=7, reg.al=pLineCount;
  176.    if ( 3 < va_arg() ) reg.ch=pTopRow, reg.cl=pLeftCol, reg.dh=pBottomRow, reg.dl=pRightCol;
  177.    else reg.ch=reg.cl=0, reg.dh=ScreenSize().row-1, reg.dl=ScreenSize().col-1;
  178.    if ( 3 == va_arg() ) slForeColor = pTopRow, slBackColor = pLeftCol;
  179.    else if ( 5 < va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  180.    reg.bh=slForeColor|(slBackColor<<4);
  181.    interrupt(0x10,reg);
  182. }
  183.  
  184.  
  185. TextBox(pTopRow,pLeftCol,pBottomRow,pRightCol,pForeColor,pBackColor,pTreatment)
  186. {
  187.    lSaveCursor = GetCursorType();
  188.    SetCursorType(HIDE_CURSOR);
  189.    if ( 5 < va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  190.    lTreatment = ( 1 & va_arg() ) ? lTreatment = va_arg(va_arg()-1) : 0 ;
  191.    // If supposed to fill the entire box then do whole box now
  192.    if !(lTreatment & NOFILL)
  193.       Scroll(0,pTopRow,pLeftCol,pBottomRow,pRightCol);
  194.    if ( lTreatment & Shadow ) {
  195.       lSaveFore = slForeColor, lSaveBack = slBackColor;
  196.       Scroll(0,pTopRow+1,pRightCol+1,pBottomRow+1,pRightCol+2,LIGHTGRAY,BLACK);
  197.       Scroll(0,pBottomRow+1,pLeftCol+2,pBottomRow+1,pRightCol,LIGHTGRAY,BLACK);
  198.       slForeColor = lSaveFore, slBackColor = lSaveBack;
  199.    }
  200.    // if need lines, then draw lines now
  201.    if ( lLineType = (lTreatment & (DOUBLE_LINE|SINGLE_LINE|0xFF)) ) {
  202.       if ( lLineType & 0xFF )
  203.          memset(lCorners,lLineType,4);
  204.       else
  205.          lCorners = SINGLE_LINE==lLineType ? '┌┐└┘' : '╔╗╚╝' ;
  206.       ScrWrite(lCorners[0],pTopRow,pLeftCol);
  207.       HorzLine(pTopRow,pLeftCol+1,lLen=pRightCol-pLeftCol-1,lLineType);
  208.       ScrWrite(lCorners[1]);
  209.       ScrWrite(lCorners[2],pBottomRow,pLeftCol);
  210.       HorzLine(pBottomRow,pLeftCol+1,lLen,lLineType);
  211.       ScrWrite(lCorners[3]);
  212.       VertLine(pTopRow+1,pLeftCol,lLen=pBottomRow-pTopRow-1,lLineType);
  213.       VertLine(pTopRow+1,pRightCol,lLen,lLineType);
  214.    }
  215.    SetCursorType(lSaveCursor);
  216. }
  217.  
  218. HorzLine(pRow,pLeftCol,pLen,pForeColor,pBackColor,pTreatment)
  219. {
  220.    if ( 4 < va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  221.    lTreatment = va_arg(va_arg()-1);
  222.    if ( lTreatment & 0xFF )
  223.       // fill line with plain text character
  224.       memset(lBuf,lTreatment,pLen);
  225.    else
  226.       // special line-drawing character for single or double line
  227.       memset(lBuf,SINGLE_LINE==lTreatment ? '─' : '═',pLen);
  228.    ScrWrite(lBuf,pRow,pLeftCol);
  229. }
  230.  
  231. VertLine(pTopRow,pCol,pLen,pForeColor,pBackColor,pTreatment)
  232. {
  233.    if ( 4 < va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  234.    lTreatment = va_arg(va_arg()-1);
  235.    if ( lTreatment & 0xFF )
  236.       reg.al = lTreatment;
  237.    else
  238.       reg.al = SINGLE_LINE==lTreatment ? '│' : '║' ;
  239.    // write each character going down
  240.    reg.ah=9, reg.bh=0, reg.cx=1, reg.bl=slForeColor|(slBackColor<<4);
  241.    lRow=pTopRow, lLen=pLen;
  242.    while lLen--  ScreenCursor(pCol,lRow++), interrupt(0x10,reg,outreg);
  243. }
  244.  
  245.  
  246. GetScreenData()
  247. {
  248.    #define VIDEO_PORT_ADDDR_PTR  0x463
  249.    #define MONO_CARD_PORT        0x3B4
  250.    lVideoMemory = ( MONO_CARD_PORT == peek(VIDEO_PORT_ADDDR_PTR,UWORD16) )
  251.                    ? 0xB0000000 : 0xB8000000 ;
  252.    #define CURRENT_PAGE_OFFSET_PTR  0x44E
  253.    lVideoMemory += peek(CURRENT_PAGE_OFFSET_PTR,UWORD16);
  254.  
  255.    lScreenCount = ScreenSize().col * ScreenSize().row;
  256.  
  257.    BLObSize(lScreenData,lScreenCount);
  258.  
  259.    // The following assembly routine takes the following input:
  260.    //    ax:bx is screen seg:offset
  261.    //    cx:dx is lScreenData seg:offset
  262.    //    First word in lScreenData is number of bytes, the assembly code
  263.    //    would look like this:
  264.    //             MOV   DS,AX    8ED8
  265.    //             MOV   SI,BX    89DE
  266.    //             MOV   ES,CX    8EC1
  267.    //             MOV   DI,DX    89D7
  268.    //             ES:            26
  269.    //             MOV   CX,[DI]  8B0D
  270.    //             CLD            FC
  271.    //       CPY:  MOVSB          A4
  272.    //             INC   SI       46
  273.    //             LOOP  CPY:     E2FC
  274.    //             RETF           CB
  275.    BLObPut(lScreenData,0,lScreenCount,UWORD16);
  276.    asm("\x8E\xD8\x89\xDE\x8E\xC1\x89\xD7\x26\x8B\x0D\xFC\xA4\x46\xE2\xFC\xCB",
  277.        segment(lVideoMemory),offset(lVideoMemory),
  278.        segment(lScreenData),offset(lScreenData));
  279.  
  280.    return lScreenData;
  281. }
  282.  
  283.